package com.blb.day1thread;

public class ThreadTest4 {

    static Thread thread1 = null;
    static Thread thread2 = null;

    public static void main(String[] args) {
        thread1 = new Thread(()->{
           for (int i = 0;i < 100;i++){
               try {
                   //合并thread2线程
                   if(i == 30){
                       thread2.join();
                   }
                   Thread.sleep(10);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
               System.out.println("线程1执行了"+i);
           }
        });
        thread1.start();
        thread2 = new Thread(()->{
            for (int i = 0;i < 100;i++){
                try {
                    //合并thread1线程
                    if(i == 30){
                        thread1.join();
                    }
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("线程2执行了"+i);
            }
        });
        thread2.start();
    }
}
